home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Meeting Pearls 2
/
Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso
/
Pearls
/
dev
/
Oberon4Amiga
/
Dialogs
/
DialogStaticTexts.Mod
(
.txt
)
< prev
next >
Wrap
Oberon Text
|
1994-11-28
|
7KB
|
168 lines
Syntax10.Scn.Fnt
Syntax10i.Scn.Fnt
StampElems
Alloc
27 Oct 94
Syntax10b.Scn.Fnt
Chicago10.Scn.Fnt
MODULE DialogStaticTexts;
(** Markus Knasm
ller 22.Jun.94 -
IMPORT DialogFrames, Dialogs, DialogTexts, Display, Files, Fonts, GraphicUtils, In, Oberon, TextFrames, Texts, Viewers;
CONST MM = 1; W* = 40; H* = 20;
TYPE
Item* = POINTER TO ItemDesc;
ItemDesc* = RECORD(Dialogs.ObjectDesc)
fnt-: Fonts.Font; (** the font with which the text is shown *)
s-: ARRAY 64 OF CHAR; (** the text which is shown *)
END;
VAR w0: Texts.Writer;
PROCEDURE (t: Item) Draw* (x, y: INTEGER; clipFrame: Display.Frame);
(** displays the object at (x, y) in frame f *)
VAR ox, oy, w, h, yh, cx, mode: INTEGER;
BEGIN
t.GetDim (ox, oy, w, h);
IF t.selected THEN mode := Display.invert ELSE mode := Display.paint END;
yh := y + (h DIV 2) - ((t.fnt.minY + t.fnt.maxY) DIV 2);
IF h - (yh - y) > t.fnt.maxY THEN GraphicUtils.DrawString (clipFrame, t.s, x+ 3, yh, w - 4, t.fnt, mode, cx) END;
END Draw;
PROCEDURE (t: Item) Copy* (VAR dup: Dialogs.Object);
(** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
VAR x: Item;
BEGIN
IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END;
t.Copy^ (dup); x.fnt := t.fnt; COPY (t.s, x.s);
END Copy;
PROCEDURE (t: Item) Load* (VAR r: Files.Rider);
(** reads the object from rider r *)
VAR fntname: ARRAY 32 OF CHAR;
BEGIN t.Load^ (r); Files.ReadString (r, fntname); t.fnt := Fonts.This (fntname); Files.ReadString (r, t.s) ;
END Load;
PROCEDURE (t: Item) Store* (VAR r: Files.Rider);
(** writes the object to rider r *)
BEGIN t.Store^ (r); Files.WriteString (r, t.fnt.name); Files.WriteString (r, t.s);
END Store;
PROCEDURE (t: Item) Print* (x, y: INTEGER);
(** prints the object at printer coordinates (x, y) *)
VAR w, h, ox, oy, yh, cx: INTEGER;
BEGIN
t.GetPDim (ox, oy, w, h);
cx := (t.fnt.minY + t.fnt.maxY) DIV 2; cx := SHORT (cx * Dialogs.dUnit DIV Dialogs.pUnit);
yh := y + (h DIV 2) - cx;
IF h - (yh - y) > t.fnt.maxY THEN GraphicUtils.PrintString (t.s, x + 3, yh, w- 4, t.fnt, cx) END
END Print;
PROCEDURE (t: Item) SetFont* (fnt: Fonts.Font);
(** sets the font with which the text is shown *)
BEGIN t.Hide; t.fnt := fnt; t.Restore; IF t.panel # NIL THEN t.panel.MarkMenu END
END SetFont;
PROCEDURE (t: Item) SetString* (s: ARRAY OF CHAR);
(** sets the text which is shown *)
BEGIN t.Hide; COPY (s, t.s); t.Restore; IF t.panel # NIL THEN t.panel.MarkMenu END
END SetString;
PROCEDURE (t: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg);
(** handles messages which were sent to frame f *)
VAR t1: Texts.Text;
BEGIN
t.Handle^ (f, m);
WITH f: DialogFrames.Frame DO
WITH m: Oberon.InputMsg DO
IF (m.id = Oberon.track) & (m.keys = {MM}) & (t.cmd[0] # 0X) THEN
DialogTexts.GetParText (t.par, t.panel, t1);
t.CallCmd (f, Viewers.This (m.X, m.Y), t1)
END
ELSE
END
ELSE
END
END Handle;
PROCEDURE WriteToObjectStr (o: DialogTexts.Item; n: ARRAY OF CHAR);
VAR t: Texts.Text;
BEGIN
t := o.GetText (); Texts.WriteString (w0, n); Texts.Append (t, w0.buf);
END WriteToObjectStr;
PROCEDURE (t: Item) Edit* ();
(** opens a dialog for editing the properties of the object *)
VAR on: Dialogs.Object; os, string: DialogTexts.Item; s: Item; p: Dialogs.Panel; t1: Texts.Text; fnt: Fonts.Font;
BEGIN
t.Edit^ (); p := Dialogs.editPanel;
NEW (string); string.Init;
string.SetName ("string"); string.SetDim (245, -40, 140, 25, FALSE); p.Insert (string, FALSE);
(* ---- *) ASSERT (Dialogs.res = Dialogs.ok);
NEW (s); s.Init; s.SetDim (196, -36, 45, 20, FALSE);
s.SetString ("String"); fnt := Fonts.This ("Syntax12b.Scn.Fnt"); s.SetFont (fnt);
p.Insert (s, FALSE);
(* ---- *) ASSERT (Dialogs.res = Dialogs.ok);
WriteToObjectStr (string, t.s);
t1 := string.GetText (); Texts.ChangeLooks (t1, 0, t1.len, {0}, t.fnt, 0, 0);
END Edit;
PROCEDURE (t: Item) Update* (p: Dialogs.Panel);
(** sets the properties of the object to the values defined in the dialog p opened with Edit *)
VAR os: Dialogs.Object; t1: Texts.Text; r: Texts.Reader; ch: CHAR; str: ARRAY 64 OF CHAR; i: INTEGER;
BEGIN
t.Update^ (p);
os := p.NamedObject ("string"); t1 := os(DialogTexts.Item).GetText ();
Texts.OpenReader (r, t1, 0); Texts.Read (r, ch); i := 0;
IF (r.fnt # NIL) & (r.fnt # t.fnt) THEN t.SetFont (r.fnt) END;
WHILE ~ r.eot DO
str[i] := ch; INC (i); Texts.Read (r, ch);
END;
str[i] := 0X;
IF str # t.s THEN t.SetString (str) END
END Update;
PROCEDURE Insert*;
(** Insert ([name] [x y w h] | ^ ) inserts a static text - item in the panel containing the caret position *)
VAR x, y, x1, y1, w, h: INTEGER; t: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR;
BEGIN
NEW (t);
DialogFrames.GetCaretPosition(p, x, y);
IF (p # NIL) THEN
t.Init; t.fnt := Fonts.This ("Syntax10b.Scn.Fnt");
In.Open; In.Name (name);
IF ~In.Done THEN COPY ("", name); In.Open END;
COPY (name, t.s); t.SetName (name);
In.Int (x1); In.Int (y1); In.Int (w); In.Int (h);
IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H
ELSE
IF w < 0 THEN w := W END;
IF h < 0 THEN h := H END
END;
t.SetDim (x1, y1, w, h, FALSE); p.Insert (t, FALSE);
ELSE
Dialogs.res := Dialogs.noPanelSelected
END;
IF Dialogs.res # 0 THEN Dialogs.Error ("DialogStaticTexts") END;
END Insert;
PROCEDURE SetString*;
(** SetString (str | ^) sets the string of the static text item at the caret to str *)
VAR o: Dialogs.Object; p: Dialogs.Panel; str: ARRAY 64 OF CHAR;
BEGIN
In.Open; In.Name (str);
IF ~ In.Done THEN
Dialogs.res := Dialogs.wrongInput
ELSE
DialogFrames.FindObject (o, p);
IF (Dialogs.res = Dialogs.ok) & (o IS Item) THEN
o(Item).SetString (str); o(Item).SetFont (Fonts.This ("Syntax10b.Scn.Fnt"))
END
END;
IF Dialogs.res # Dialogs.ok THEN Dialogs.Error ("DialogStaticTexts") END
END SetString;
PROCEDURE GetString*;
(** writes the component s of the static text item under the caret to the log viewer *)
VAR o: Dialogs.Object; p: Dialogs.Panel; str: ARRAY 64 OF CHAR;
BEGIN
DialogFrames.FindObject (o, p);
IF Dialogs.res = Dialogs.ok THEN
IF o IS Item THEN
COPY (o(Item).s, str);
Texts.WriteString (w0, "String:"); Texts.WriteString (w0, str); Texts.WriteLn (w0);
Texts.Append (Oberon.Log, w0.buf)
ELSE
Dialogs.res := Dialogs.objectNotFound
END
END;
IF Dialogs.res # Dialogs.ok THEN Dialogs.Error ("DialogStaticTexts") END
END GetString;
BEGIN Texts.OpenWriter (w0)
END DialogStaticTexts.